<template>
  <section class="webview fixHeight">
    <el-scrollbar style="height:100%">
      <div class="search">
        <div class="content">
          <div class="part1">
            <div class="item">
              <span class="name">关键字</span>
              <el-input
                v-model="detail.title"
                class="input margin-left"
                placeholder="关键字"
                maxlength="20"
                @keyup.enter.native="search"
              />
            </div>
            <div class="searchItem">
              <el-button type="success" round class="search-btn" @click="getList">搜索</el-button>
              <!-- <el-button round class="add" style="margin-left:20px;" @click="$router.push('/configure/add')">新增</el-button> -->
            </div>
          </div>
        </div>
      </div>
      <div class="table margin-top padding-bottom">
        <el-table
          ref="multipleTable"
          empty-text="暂无数据"
          :data="list"
          style="width: 100%"
          :row-style="{background: '#FCFDFF'}"
          :header-cell-style="{background:'#46705D',color:'#ffffff'}"
          @select-all="handleSelectAll"
          @selection-change="handleSelectionChange"
        >
          <el-table-column
            type="selection"
            width="55"
          />
          <el-table-column fixed type="index" label="序号" :show-overflow-tooltip="true" align="center" />
          
          <el-table-column label="配置名称" :show-overflow-tooltip="true" align="center">
            <template slot-scope="scope">
              <div>{{ scope.row.name }}</div>
            </template>
          </el-table-column>
          <el-table-column label="描述" :show-overflow-tooltip="true" align="center">
            <template slot-scope="scope">
              <div>{{ scope.row.remark }}</div>
            </template>
          </el-table-column> 
		  <el-table-column label="修改时间" :show-overflow-tooltip="true" align="center">
            <template slot-scope="scope">
              <div>{{ scope.row.createAt }}</div>
            </template>
          </el-table-column>
		  <el-table-column fixed="right" label="操作" :show-overflow-tooltip="true" align="center" width="250">
		    <template slot-scope="scope">
		      <el-button type="text" size="small" @click="toSee(scope.row)">修改</el-button>
		    </template>
		  </el-table-column>
        </el-table>
        <div class="pageContain margin-top">
			 <div style="flex: 1;text-align: right;">共{{pagination.total}}条</div>
          <el-pagination
            :current-page="pagination.page"
            :page-size="pagination.pageSize"
            :background="true"
            layout="prev, pager, next"
            :total="pagination.total"
            @current-change="handleCurrentChange"
          />
        </div>
      </div>
    </el-scrollbar>
  </section>
</template>
<script>
import { configList } from '@/api/api'
export default {
  data() {
    return {
      list: [],
      pagination: {
        pageSize: 10,
        page: 1,
        total: 0
      },
      detail: {
        title: '',
        templateType: ''
      },
      ids: []
    }
  },
  created() {
    this.getList()
  },
  methods: {
	  toSee(item){
		   this.$router.push({ path: '/configure/add', query: { item: JSON.stringify(item) }})
	  },
	  getList() {
		  const params = {
		    curPage: this.pagination.page,
		    pageSize: this.pagination.pageSize,
		    name: this.detail.title
		  }
      configList(params).then(data => {
        this.list = data.data.records
		 this.pagination.total = data.data.total
      })
    },
    handleSelectAll(selection) {
      this.ids = []
      if (selection.length > 0) {
        selection.forEach(item => {
          this.ids.push(item.id)
        })
      }
    },
    handleCurrentChange(val) {
      // 重置当前页码
      this.pagination.page = val
      this.getList()
    },
    handleSelectionChange(selection) {
      this.ids = []
      if (selection.length > 0) {
        selection.forEach(item => {
          this.ids.push(item.id)
        })
      }
    },
   
  }}
</script>
